﻿<%@ Page Title="Thêm/cập nhật loại sản phẩm" Language="C#" MasterPageFile="~/Admin/Admin.master" 
    AutoEventWireup="true" CodeFile="AddEditDepartment.aspx.cs" Inherits="Admin_AddEditDepartment" %>
<%@ Import Namespace="DTO" %>
<%@ Register Assembly="FredCK.FCKeditorV2" Namespace="FredCK.FCKeditorV2" TagPrefix="FCKeditorV2" %>
<%@ Register Src="~/Controls/AsyncFileUpload.ascx" TagPrefix="uc1" TagName="AsyncFileUpload" %>
<%@ Register Src="~/Controls/AsyncFileUploadSimple.ascx" TagPrefix="uc2" TagName="AsyncFileUploadSimple" %>



<asp:Content ID="Content1" ContentPlaceHolderID="LeftContent" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
    <div class="title">
  <asp:Literal runat="server" ID="lblNewProduct" Text="thêm mới" />
  <asp:Literal runat="server" ID="lblEditProduct" Text="cập nhật" Visible="false" />
</div>
<div class="body"> 
<ul style="list-style-type: circle">
    <li>
        <asp:HyperLink ID="HyperLink1" runat="server" Text="Manage Departments" NavigateUrl="~/Admin/ManageDepartments.aspx"></asp:HyperLink>
    </li>
</ul>
<hr />   
<p></p>
<asp:DetailsView ID="dvwDepartment" runat="server" AutoGenerateRows="False" 
        Width="100%" Height="50px" DataSourceID="objCurrDepartment"
HeaderText="<b>Category Details</b>"  DataKeyNames="ID" DefaultMode="Insert" ondatabound="dvwDepartment_DataBound" 
        oniteminserting="dvwDepartment_ItemInserting" 
        onitemupdating="dvwDepartment_ItemUpdating">
    <Fields>
        <asp:BoundField DataField="ID" HeaderText="ID" ReadOnly="True" SortExpression="ID" InsertVisible="False" />
         <asp:BoundField DataField="AddedDate" HeaderText="AddedDate" InsertVisible="False"
            ReadOnly="True" SortExpression="AddedDate" />
         <asp:BoundField DataField="AddedBy" HeaderText="AddedBy" InsertVisible="False" ReadOnly="True"
            SortExpression="AddedBy" />       
         <asp:TemplateField HeaderText="Title" SortExpression="Title">
            <ItemTemplate>
               <asp:Label ID="lblTitle" runat="server" Text='<%# Eval("Title") %>'></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
               <asp:TextBox ID="txtTitle" runat="server" Text='<%# Bind("Title") %>' MaxLength="256" Width="100%"></asp:TextBox>
               <asp:RequiredFieldValidator ID="valRequireTitle" runat="server" 
                    ControlToValidate="txtTitle" SetFocusOnError="true"
                  Text="Tên lại sản phẩm không được bỏ trống." 
                    ToolTip="The Title field is required." Display="Dynamic"></asp:RequiredFieldValidator>
            </EditItemTemplate>
         </asp:TemplateField>
         
         <asp:TemplateField HeaderText="Importance" SortExpression="Importance">
            <ItemTemplate>
               <asp:Label ID="lblImportance" runat="server" Text='<%# Eval("Importance") %>'></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
               <asp:TextBox ID="txtImportance" runat="server" Text='<%# Bind("Importance") %>' MaxLength="256" Width="100%"></asp:TextBox>
               <asp:RequiredFieldValidator ID="valRequireImportance" runat="server" 
                    ControlToValidate="txtImportance" SetFocusOnError="true"
                  Text="Mức độ quan trọng không được để trống." 
                    ToolTip="The Importance field is required." Display="Dynamic"></asp:RequiredFieldValidator>
               <asp:CompareValidator ID="valImportanceType" runat="server" 
                    Operator="DataTypeCheck" Type="Integer"
                  ControlToValidate="txtImportance" Text="Mức độ quan trọng phải là số nguyên."
                  ToolTip="The Importance must be an integer." Display="dynamic" />
            </EditItemTemplate>
         </asp:TemplateField>
         
         <asp:TemplateField HeaderText="Loại sản phẩm" SortExpression="DepartmentID">
            <ItemTemplate>
                <asp:Label runat="server" ID="lblDepartment" Text='<%#Eval("FullTitle") %>' />
            </ItemTemplate>
            <EditItemTemplate>
                <asp:DropDownList runat="server"  ID="ddlDepartments"  DataSourceID="objAllDepartments" DataTextField="FullTitle" Width="30%" />
                <asp:ObjectDataSource runat="server" ID="objAllDepartments" TypeName="BLL.Store.Department" SelectMethod="ListDepartments"></asp:ObjectDataSource>
            </EditItemTemplate>
         </asp:TemplateField>

         <asp:TemplateField HeaderText="Image" ConvertEmptyStringToNull="False">
            <ItemTemplate>
               <asp:Image ID="imgImage" runat="server" ImageUrl='<%# Eval("ImageUrl") %>' 
                  AlternateText='<%# Eval("Title") %>'
                  Visible='<%# !string.IsNullOrEmpty(DataBinder.Eval(Container.DataItem, "ImageUrl").ToString()) %>' />
            </ItemTemplate>
            <EditItemTemplate>
                <%--<uc1:AsyncFileUpload runat="server" ID="AsyncFileUpload" pictureId='<%# Bind("PictureID") %>' />--%>
                <uc2:AsyncFileUploadSimple runat="server" id="AsyncFileUploadSimple1"  />
            </EditItemTemplate>
         </asp:TemplateField>
         
         <asp:TemplateField HeaderText="Description" SortExpression="Description" ConvertEmptyStringToNull="False">
            <ItemTemplate>
               <asp:Label ID="lblDescription" runat="server" Text='<%# Eval("Description") %>' Width="100%"></asp:Label>
            </ItemTemplate>
            <EditItemTemplate>
               <FCKeditorV2:FCKeditor ID="FCKeditor1" BasePath="~/fckeditor/" runat="server" Value='<%# Bind("Description") %>' 
               ToolbarSet="Basic" Height="200px" Width="100%" />               
            </EditItemTemplate>
         </asp:TemplateField>
           <asp:CommandField ButtonType="Image" CancelImageUrl="~/Images/nhaplai.png" 
              CancelText="Nhập  lại" InsertImageUrl="~/Images/themmoi.png" 
              InsertText="Thêm mới" ShowInsertButton="True" ShowEditButton="True"
              UpdateImageUrl="~/Images/capnhat.png" UpdateText="Cập nhật" />        
    </Fields>
</asp:DetailsView>

<asp:ObjectDataSource ID="objCurrDepartment" runat="server" InsertMethod="InsertDepartment" SelectMethod="GetDepartmentByID" TypeName="BLL.Store.Department" UpdateMethod="UpdateDepartment">
      <SelectParameters>
           <asp:QueryStringParameter Name="departmentID" QueryStringField="ID" 
               Type="Int32" />
      </SelectParameters>
      <InsertParameters>
        <asp:Parameter  Name="title" Type="String" ConvertEmptyStringToNull="false" />
        <asp:Parameter  Name="importance" Type="Int32" />
        <asp:Parameter  Name="description" Type="String" ConvertEmptyStringToNull="false" />
        <asp:Parameter Name="ParentID" Type="Int32" />         
        <asp:Parameter Name="PictureID" Type="Int32" /> 
      </InsertParameters>
      <UpdateParameters>
        <asp:Parameter Name="id" Type="Int32" />
        <asp:Parameter  Name="title" Type="String" ConvertEmptyStringToNull="false" />
        <asp:Parameter  Name="importance" Type="Int32" />
        <asp:Parameter  Name="description" Type="String" ConvertEmptyStringToNull="false" />
          <asp:Parameter Name="ParentID" Type="Int32" />
          <asp:Parameter Name="PictureID" Type="Int32" />
      </UpdateParameters>
   </asp:ObjectDataSource>    
</div>   
<div class="bottom"></div>
</asp:Content>

